package com.qijian.maindata.domain.vo;

import com.qijian.common.utils.ObjectUtils;
import lombok.Data;
import lombok.ToString;

import java.math.BigDecimal;

@Data
@ToString
public class ProjectProcessVo {
    private String type;
    private String typeName;
    private BigDecimal workCost;
    private BigDecimal completeCost;
    private BigDecimal preCost;
    private BigDecimal percentage;
    private BigDecimal prePercentage;

    public BigDecimal getPercentage() {
        if (ObjectUtils.isNull(workCost) || ObjectUtils.isNull(completeCost) || BigDecimal.ZERO.compareTo(completeCost) == 0) {
            return BigDecimal.ZERO;
        }
        return completeCost.divide(workCost, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
    }

    public BigDecimal getPrePercentage() {
        if (ObjectUtils.isNull(workCost) || ObjectUtils.isNull(preCost) || BigDecimal.ZERO.compareTo(preCost) == 0) {
            return BigDecimal.ZERO;
        } else if (completeCost.compareTo(preCost) > 0) {
            return completeCost.divide(workCost, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
        }
        return preCost.divide(workCost, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
    }
}
